﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using motelmanagement.common;
using System.Data;
using System.Data.OleDb;
namespace motelmanagement.dao
{
    class ServiceDAO
    {
        SqlUtil sqlUtil = new SqlUtil();
        OleDbCommand cmd = null;
        private string strSql = null;

        public DataTable getAllService() {
            cmd = new OleDbCommand("Select * from Service");
            sqlUtil.Load(cmd);
            return sqlUtil;
        }

        public DataTable getService(int id)
        {
            cmd = new OleDbCommand("Select * from Service Where service_id = @id");
            cmd.Parameters.Add("id",SqlDbType.Int).Value= id;
            sqlUtil.Load(cmd);
            return sqlUtil;
        }
        public void insertService(string svName, string svUnit, int svPrice) {
            strSql = "Insert Into Service(service_name,service_unit,service_price)";
            strSql += " Values(@name,@unit,@price)";
            cmd = new OleDbCommand(strSql);
            cmd.Parameters.Add("name", SqlDbType.NText).Value = svName;
            cmd.Parameters.Add("unit", SqlDbType.NText).Value = svUnit;
            cmd.Parameters.Add("price", SqlDbType.Int).Value = svPrice;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void updateService(int id,string svName, string svUnit, int svPrice)
        {
            strSql = "Update Service Set service_name = @name,service_unit = @unit,service_price = @price)";
            strSql += " Where service_id = @id";
            cmd = new OleDbCommand(strSql);
            cmd.Parameters.Add("name", SqlDbType.NText).Value = svName;
            cmd.Parameters.Add("unit", SqlDbType.NText).Value = svUnit;
            cmd.Parameters.Add("price", SqlDbType.Int).Value = svPrice;
            cmd.Parameters.Add("id", SqlDbType.Int).Value = id;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void deleteService(int id)
        {
            strSql = "Delete From Service Where service_id = @id";
            cmd = new OleDbCommand(strSql);
            cmd.Parameters.Add("id", SqlDbType.Int).Value = id;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
    }
}
